package it.xiuxian.personcenter.presenter

import android.os.Build
import android.widget.Toast
import androidx.annotation.RequiresApi
import com.alibaba.android.arouter.launcher.ARouter
import com.lzy.okgo.OkGo
import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.model.Response
import it.xiuxian.lib.base.BaseBean
import it.xiuxian.lib.base.BasePresenter
import it.xiuxian.lib.base.ILoadBind
import it.xiuxian.lib.bean.NewPersonBean
import it.xiuxian.lib.http.CallBackOption
import it.xiuxian.lib.http.HttpConfig
import it.xiuxian.lib.utils.AESUtils
import it.xiuxian.personcenter.activity.MyDatumActivity
import org.json.JSONObject

class MyDatumActivityPresenter: BasePresenter<MyDatumActivity>() {
    fun getHomePage(){
        OkGo.post<BaseBean<NewPersonBean>>(HttpConfig.BASE_URL+"/appuser/info")
            .execute(object : CallBackOption<BaseBean<NewPersonBean>>() {}.loadBind(mView as MyDatumActivity).execute(
                object : ILoadBind<BaseBean<NewPersonBean>> {
                    override fun excute(bean: BaseBean<NewPersonBean>) {
                        if(bean.code==0){
                            (mView as MyDatumActivity).setUI(bean.data)
                        }
                    }
                }
            ))
    }
   @RequiresApi(Build.VERSION_CODES.O)
   fun submit(qianming:String, nickname:String){
       val json1 = JSONObject()
       json1.put("qianming",qianming)
           .put("nickname",nickname)
       val s = AESUtils.encryptAES_ECB(json1.toString())
        OkGo.post<BaseBean<String>>(HttpConfig.BASE_URL+"/appuser/updateMessage")
            .params("encrypt", s)
            .execute(object : CallBackOption<BaseBean<String>>() {}.loadBind(mView as MyDatumActivity).execute(
                object : ILoadBind<BaseBean<String>> {
                    override fun excute(bean: BaseBean<String>) {
                            (mView as MyDatumActivity).setdata(bean.msg)

                    }
                }
            ))
    }
}